package gvo.dbinfo;
import java.util.TreeSet;

public class TableInfo {
	public static String UNDERLINE = "==================================================";
	public String tableName;
	public TreeSet<SarFieldInfo> fields = new TreeSet<SarFieldInfo>();

	public TableInfo(String pName) {
		tableName = pName;
	}

	public SarFieldInfo getField(String in) {
		for (SarFieldInfo fi : fields) {
			if (fi.fieldName.equals(in)) {
				return fi;
			}
		}
		return null;
	}
	public String[] getFieldNames(){
		int size = fields.size();
		String[] res;
		int i=0;
		
			res = new String[size];
		for (SarFieldInfo fi : fields) {
			res[i++]=fi.fieldName;
		}
		
		return res;
	}
	public void printTableInfo() {
		int lenUL = UNDERLINE.length();
		int lenTN;
		System.out.println();
		lenTN = tableName.length() + 7;
		if (lenUL < lenTN) {
			lenTN = lenUL - 1;
		}
		System.out.println("Table: " + tableName);
		System.out.println(UNDERLINE.substring(0, lenTN));
		for (SarFieldInfo fi : fields) {
			System.out.println(fi.printInfo());
		}
	}
	
	public String toString(){
		return tableName;
	}
}